package com.gitee.dolt.utils;

import cn.hutool.core.util.ArrayUtil;

import java.math.BigDecimal;

public class NumberUtils {
    public static final int NUM_255 = 255;
    public static final int NUM_65535 = 65535;

    public static Integer add(Integer... values) {
        Integer result = null;
        for (Integer value : values) {
            if (value == null) {
                continue;
            }
            if (result == null) {
                result = 0;
            }
            result += value;
        }
        return result;
    }

    public static BigDecimal add(BigDecimal... values) {
        BigDecimal result = null;
        for (BigDecimal value : values) {
            if (value == null) {
                continue;
            }
            if (result == null) {
                result = BigDecimal.ZERO;
            }
            result = result.add(value);
        }
        return result;
    }

    public static Integer sub(Integer... values) {
        Integer result = ArrayUtil.get(values, 0);
        for (int i = 1; i < values.length; i++) {
            Integer value = values[i];
            if (value == null) {
                continue;
            }
            if (result == null) {
                result = 0;
            }
            result -= value;
        }
        return result;
    }
}
